package LeetCode.month02.day43;

import java.util.HashSet;
import java.util.Set;

public class No219 {
    public boolean containsNearbyDuplicate(int[] nums, int k) {
        int n = nums.length;
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            if(set.contains(nums[i])) return true;
            set.add(nums[i]);
            if(i<k) continue;
            set.remove(nums[i-k]);
        }
        return false;
    }
}
